#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "datamodel.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    QObject::connect(
        &engine,
        &QQmlApplicationEngine::objectCreationFailed,
        &app,
        []() { QCoreApplication::exit(-1); },
        Qt::QueuedConnection);

    // 创建数据模型实例
    DataModel *model = new DataModel(&engine);
    
    // 将模型暴露给QML
    engine.rootContext()->setContextProperty("dataModel", model);

    engine.loadFromModule("qml_listview_cpp", "Main");

    return app.exec();
}
